package com.ifish.leetcode.problem;

/**
 * Created by iFish on 2017/7/8.
 */

public abstract class BaseLeetCodeProblem implements LeetCodeRunnable {

    private boolean mLog = true;

    public abstract String title();

    public int difficulty() {
        return 0;
    }

    public void setNeedLog(boolean log) {
        mLog = log;
    }

    @Override
    public void run() {
        if (!mLog) return;

        System.out.print("--------");
        System.out.println();
        System.out.print(String.format("%s: [%s] %s", getRunnerName(), getDifficulty(), title()));
        System.out.println();
    }

    protected void printResult(boolean val) {
        if (!mLog) return;
        System.out.print(val);
    }

    protected void printResult(int val) {
        if (!mLog) return;
        System.out.print(val);
    }

    protected void printResult(String str) {
        if (!mLog) return;
        System.out.print(str);
    }

    private String getDifficulty() {
        int difficulty = difficulty();
        switch (difficulty) {
            case 1: return "M";
            case 2: return "H";
            default: return "E";
        }
    }

    private String getRunnerName() {
        String className = this.getClass().getSimpleName();
        if (className.startsWith("_")) {
            className = className.substring(1);
        }
        return className;
    }
}
